using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace OsdmSoftware.CommonLibrary
{
    public partial class FloatingForm: Form
    {
        bool move;
        Point offset;
        Form parentForm;
        Control mainControl;
        //bool isActivating = false;

        public Control MainControl { get { return mainControl; } set { mainControl = value; } }

        public Form MyParentForm { get { return parentForm; } set { parentForm = value; } }

        public FloatingForm(Control mainControl, Form parentForm)
        {
            InitializeComponent();
            this.parentForm = parentForm;
            TopMost = true;
            ClientSize = new Size(mainControl.Width, mainControl.Height + panel1.Height);
            mainControl.Dock = DockStyle.Fill;
            Controls.Add(mainControl);
            mainControl.BringToFront();
            this.mainControl = mainControl;
#if !PocketPC
            this.ShowInTaskbar = false;
            this.StartPosition = FormStartPosition.Manual;
#endif
        }

        /*public void ActivateMe()
        {
            if (!isActivating)
            {
                isActivating = true;
                if (!parentForm.Visible)
                {
                    parentForm.Show();
                    parentForm.BringToFront();
                }
                //this.TopMost = true;
                isActivating = false;
            }
        }

        protected override void OnActivated(EventArgs e)
        {
            ActivateMe();
            base.OnActivated(e);
        }*/

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            offset = new Point(e.X, e.Y);
            move = true;
            panel1.Capture = true;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (move)
            {
                Point newPoint = panel1.PointToScreen(new Point(e.X, e.Y));
                this.Location = new Point(newPoint.X - offset.X, newPoint.Y - offset.Y);
            }
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            move = false;
            panel1.Capture = false;
        }
    }
}